package com.sz.pojo.frame;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.*;

/**
 * 题库
 */
@Entity
@Table(name = "admin_tiku")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "pojoCache")
public class Tiku extends BaseObject<Tiku> implements Comparable<Tiku> {
    //问题
    private String quesetion;
    //答案
    private String answer;
    //关键词 ，  使用 \ 分割
    private String keysWords;

    private Date time;

    public String getQuesetion() {
        return quesetion;
    }

    public void setQuesetion(String quesetion) {
        this.quesetion = quesetion;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public String getKeysWords() {
        return keysWords;
    }

    public void setKeysWords(String keysWords) {
        this.keysWords = keysWords;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((answer == null) ? 0 : answer.hashCode());
        result = prime * result + ((quesetion == null) ? 0 : quesetion.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Tiku other = (Tiku) obj;
        if (getId() == null) {
            if (other.getId() != null)
                return false;
        } else if (!getId().equals(other.getId()))
            return false;
        return true;
    }


    public static void main(String[] args) {
        List<Tiku> tikuList = new ArrayList<>();

        Tiku tiku = new Tiku();
        tiku.setId(1l);

        // if (!tikuList.contains(tiku)) {
        tikuList.add(tiku);
        // }
        Tiku tiku2 = new Tiku();
        tiku2.setId(1l);
        // if (!tikuList.contains(tiku2)) {
        tikuList.add(tiku2);
        // }
        Tiku tiku3 = new Tiku();
        tiku3.setId(2l);
        // if (!tikuList.contains(tiku3)) {
        tikuList.add(tiku3);
        // }

        Set<Tiku> tikuSet = new HashSet<>();
        tikuSet.addAll(tikuList);

        List<Tiku> tikuList1 = new ArrayList<>(tikuSet);
        System.out.println(Arrays.toString(tikuList1.toArray()));
    }

    @Override
    public String toString() {
        return "Tiku [quesetion=" + quesetion + ", answer=" + answer + ", id=" + getId() + "]";
    }

    @Override
    public int compareTo(Tiku o) {
        return Double.compare(o.getId(), getId());
    }
}
